<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>游戏规则 - 龙虎斗</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            background-attachment: fixed;
            min-height: 100vh;
            color: #333;
            transition: background 0.3s ease;
        }

        /* 主题颜色样式 */
        body.theme-blue {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-green {
            background: linear-gradient(135deg, #56ab2f 0%, #a8e6cf 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-orange {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-purple {
            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-pink {
            background: linear-gradient(135deg, #fa709a 0%, #fee140 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-red {
            background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-yellow {
            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-cyan {
            background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-lime {
            background: linear-gradient(135deg, #d299c2 0%, #fef9d7 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-indigo {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-teal {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-rose {
            background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-amber {
            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-emerald {
            background: linear-gradient(135deg, #56ab2f 0%, #a8e6cf 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-sky {
            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%) !important;
            background-attachment: fixed !important;
        }

        body.theme-violet {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
            background-attachment: fixed !important;
        }

        .container {
            max-width: 480px;
            margin: 0 auto;
            background: transparent;
            min-height: 100vh;
            position: relative;
        }

        .header {
            background: rgba(102, 126, 234, 0.9);
            backdrop-filter: blur(10px);
            color: white;
            padding: 20px;
            text-align: center;
            position: relative;
            border-bottom: 1px solid rgba(255, 255, 255, 0.2);
        }

        .back-btn {
            position: absolute;
            left: 20px;
            top: 50%;
            transform: translateY(-50%);
            background: rgba(255, 255, 255, 0.2);
            border: none;
            color: white;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            font-size: 18px;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            backdrop-filter: blur(10px);
        }

        .header h1 {
            font-size: 20px;
            font-weight: 600;
            margin: 0;
        }

        .rules-content {
            padding: 20px;
        }

        /* 规则章节 */
        .rule-section {
            background: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(10px);
            border-radius: 18px;
            padding: 25px;
            margin-bottom: 20px;
            border: 1px solid rgba(233, 236, 239, 0.8);
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }

        .rule-title {
            color: #495057;
            font-size: 18px;
            margin-bottom: 20px;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 12px;
            padding-bottom: 12px;
            border-bottom: 2px solid #e9ecef;
        }

        .rule-content {
            color: #495057;
            line-height: 1.6;
            font-size: 15px;
        }

        .rule-content p {
            margin-bottom: 15px;
        }

        .rule-content ul {
            margin: 15px 0;
            padding-left: 25px;
        }

        .rule-content li {
            margin-bottom: 8px;
            line-height: 1.5;
        }

        .rule-content strong {
            color: #667eea;
            font-weight: 600;
        }

        /* 游戏流程 */
        .game-flow {
            display: flex;
            flex-direction: column;
            gap: 15px;
            margin: 20px 0;
        }

        .flow-step {
            display: flex;
            align-items: flex-start;
            gap: 15px;
            padding: 15px;
            background: rgba(102, 126, 234, 0.1);
            border-radius: 12px;
            border-left: 4px solid #667eea;
        }

        .step-number {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            width: 30px;
            height: 30px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
            font-size: 14px;
            flex-shrink: 0;
        }

        .step-content {
            flex: 1;
        }

        .step-title {
            font-weight: 600;
            color: #495057;
            margin-bottom: 5px;
            font-size: 16px;
        }

        .step-desc {
            color: #6c757d;
            font-size: 14px;
            line-height: 1.4;
        }

        /* 卡牌类型 */
        .card-types {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 15px;
            margin: 20px 0;
        }

        .card-type {
            background: rgba(248, 249, 250, 0.8);
            border-radius: 12px;
            padding: 20px;
            text-align: center;
            border: 2px solid rgba(233, 236, 239, 0.6);
            transition: all 0.3s ease;
        }

        .card-categories {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 20px;
            margin: 20px 0;
        }

        .card-category h4 {
            font-size: 16px;
            font-weight: 600;
            margin-bottom: 12px;
        }

        .card-category ul {
            margin: 0;
            padding-left: 20px;
        }

        .card-category li {
            margin-bottom: 6px;
            font-size: 14px;
        }

        .special-rules {
            display: flex;
            flex-direction: column;
            gap: 15px;
            margin: 20px 0;
        }

        .special-rule {
            display: flex;
            align-items: flex-start;
            gap: 15px;
            padding: 15px;
            background: rgba(102, 126, 234, 0.1);
            border-radius: 12px;
            border-left: 4px solid #667eea;
        }

        .rule-icon {
            font-size: 24px;
            flex-shrink: 0;
        }

        .rule-content {
            flex: 1;
        }

        .rule-title {
            font-weight: 600;
            color: #495057;
            margin-bottom: 5px;
            font-size: 15px;
        }

        .rule-desc {
            color: #6c757d;
            font-size: 13px;
            line-height: 1.4;
        }

        /* 提示和技巧 */
        .tips-section {
            background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
            color: white;
            border-radius: 18px;
            padding: 25px;
            margin-bottom: 20px;
        }

        .tips-title {
            font-size: 18px;
            font-weight: 700;
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            gap: 12px;
            padding-bottom: 12px;
            border-bottom: 2px solid rgba(255, 255, 255, 0.3);
        }

        .tip-item {
            display: flex;
            align-items: flex-start;
            gap: 12px;
            margin-bottom: 15px;
            padding: 12px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 10px;
        }

        .tip-item:last-child {
            margin-bottom: 0;
        }

        .tip-icon {
            font-size: 18px;
            flex-shrink: 0;
        }

        .tip-text {
            flex: 1;
            line-height: 1.5;
            font-size: 14px;
        }

        /* 响应式设计 */
        @media (max-width: 480px) {
            .card-categories {
                grid-template-columns: 1fr;
                gap: 15px;
            }

            .flow-step {
                padding: 12px;
            }

            .step-number {
                width: 28px;
                height: 28px;
                font-size: 13px;
            }

            .special-rule {
                padding: 12px;
            }

            .rule-icon {
                font-size: 20px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <button class="back-btn" onclick="goBack()">←</button>
            <h1>游戏规则</h1>
        </div>

        <div class="rules-content">
            <!-- 游戏简介 -->
            <div class="rule-section">
                <h3 class="rule-title">
                    <span>🎯</span>
                    游戏简介
                </h3>
                <div class="rule-content">
                    <p><strong>龙虎斗</strong>是一款经典的两人卡牌对战游戏，使用16张画片，分为龙、虎两类角色。玩家通过翻牌确定身份，然后按照牌面数字大小进行对战。</p>
                    <p>游戏简单易学但策略丰富，需要玩家在翻牌和出牌时做出明智的决策。</p>
                </div>
            </div>

            <!-- 基本规则 -->
            <div class="rule-section">
                <h3 class="rule-title">
                    <span>📋</span>
                    基本规则
                </h3>
                <div class="rule-content">
                    <ul>
                        <li><strong>参与人数：</strong>2人对战</li>
                        <li><strong>游戏目标：</strong>吃掉所有敌方卡牌</li>
                        <li><strong>游戏时长：</strong>每局约3-5分钟</li>
                        <li><strong>胜利条件：</strong>最终获得对方所有8张牌的一方获胜</li>
                    </ul>
                </div>
            </div>

            <!-- 牌具准备 -->
            <div class="rule-section">
                <h3 class="rule-title">
                    <span>🃏</span>
                    牌具准备
                </h3>
                <div class="rule-content">
                    <p>游戏牌为一版共16张画片，分为龙、虎两类角色：</p>
                    
                    <div class="card-categories">
                        <div class="card-category">
                            <h4 style="color: #dc3545; margin-bottom: 15px;">🐉 龙类（编号1-8）：</h4>
                            <ul>
                                <li><strong>龙王</strong> (1)</li>
                                <li><strong>神龙</strong> (2)</li>
                                <li><strong>金龙</strong> (3)</li>
                                <li><strong>青龙</strong> (4)</li>
                                <li><strong>赤龙</strong> (5)</li>
                                <li><strong>白龙</strong> (6)</li>
                                <li><strong>风雨龙</strong> (7)</li>
                                <li><strong>变形龙</strong> (8)</li>
                            </ul>
                        </div>
                        
                        <div class="card-category">
                            <h4 style="color: #495057; margin-bottom: 15px;">🐯 虎类（编号1-8）：</h4>
                            <ul>
                                <li><strong>虎王</strong> (1)</li>
                                <li><strong>东北虎</strong> (2)</li>
                                <li><strong>大头虎</strong> (3)</li>
                                <li><strong>下山虎</strong> (4)</li>
                                <li><strong>绿虎</strong> (5)</li>
                                <li><strong>妖虎</strong> (6)</li>
                                <li><strong>白虎</strong> (7)</li>
                                <li><strong>小王虎</strong> (8)</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 游戏流程 -->
            <div class="rule-section">
                <h3 class="rule-title">
                    <span>🔄</span>
                    游戏流程
                </h3>
                <div class="game-flow">
                    <div class="flow-step">
                        <div class="step-number">1</div>
                        <div class="step-content">
                            <div class="step-title">游戏准备</div>
                            <div class="step-desc">创建5排4列表格，中间第3行作为分隔行，16张卡牌背面朝上摆放</div>
                        </div>
                    </div>
                    <div class="flow-step">
                        <div class="step-number">2</div>
                        <div class="step-content">
                            <div class="step-title">确定身份</div>
                            <div class="step-desc">玩家一随机翻牌，确定双方身份（龙或虎）</div>
                        </div>
                    </div>
                    <div class="flow-step">
                        <div class="step-number">3</div>
                        <div class="step-content">
                            <div class="step-title">轮流翻牌</div>
                            <div class="step-desc">双方轮流翻牌，按照牌面数字大小进行比较</div>
                        </div>
                    </div>
                    <div class="flow-step">
                        <div class="step-number">4</div>
                        <div class="step-content">
                            <div class="step-title">胜负判定</div>
                            <div class="step-desc">最终获得对方所有8张牌的一方获胜</div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 比较规则 -->
            <div class="rule-section">
                <h3 class="rule-title">
                    <span>⚖️</span>
                    比较规则
                </h3>
                <div class="rule-content">
                    <h4 style="color: #667eea; margin: 15px 0 10px 0;">通常规则：</h4>
                    <p>按牌右上角的数字比较，<strong>数字越小牌越大</strong>（1＞2＞3……以此类推）</p>
                    
                    <h4 style="color: #667eea; margin: 15px 0 10px 0;">特殊规则：</h4>
                    <ul>
                        <li><strong>变形龙</strong> (8) 能吃<strong>虎王</strong> (1)</li>
                        <li><strong>小王虎</strong> (8) 能吃<strong>龙王</strong> (1)</li>
                    </ul>
                    
                    <div class="special-rules">
                        <div class="special-rule">
                            <div class="rule-icon">🔄</div>
                            <div class="rule-content">
                                <div class="rule-title">变形龙特权</div>
                                <div class="rule-desc">作为龙类最低牌，却拥有吃掉虎王的特殊能力</div>
                            </div>
                        </div>
                        <div class="special-rule">
                            <div class="rule-icon">👑</div>
                            <div class="rule-content">
                                <div class="rule-title">小王虎特权</div>
                                <div class="rule-desc">作为虎类最低牌，却拥有吃掉龙王的特殊能力</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 游戏界面 -->
            <div class="rule-section">
                <h3 class="rule-title">
                    <span>🖥️</span>
                    游戏界面
                </h3>
                <div class="rule-content">
                    <ul>
                        <li><strong>表格布局：</strong>页面中间创建5排4列的表格，用于放置16张纸牌</li>
                        <li><strong>分隔行：</strong>第3行（中间行）不放纸牌，作为龙虎两方的分隔行</li>
                        <li><strong>字体颜色：</strong>龙类型卡牌名字用红色字体，虎类型卡牌名字用黑色字体</li>
                        <li><strong>初始状态：</strong>游戏启动时自动洗牌和发牌，16张卡牌全部背面朝上摆放</li>
                        <li><strong>界面简化：</strong>只保留一个"重新开始游戏"按钮，游戏启动时自动准备就绪</li>
                    </ul>
                </div>
            </div>

            <!-- 游戏玩法 -->
            <div class="rule-section">
                <h3 class="rule-title">
                    <span>🎮</span>
                    游戏玩法
                </h3>
                <div class="rule-content">
                    <ul>
                        <li><strong>游戏开始：</strong>16张卡牌全部背面朝上，玩家一随机点击一张卡牌翻到正面</li>
                        <li><strong>确定身份：</strong>如果玩家一的第一张卡牌是龙，该回合玩家一的手牌类型就是龙，玩家二的手牌类型就是虎</li>
                        <li><strong>轮流翻牌：</strong>玩家二随机点击一张卡牌翻面，双方轮流进行</li>
                        <li><strong>身份反转：</strong>如果玩家一翻出的是虎牌，则身份相反</li>
                        <li><strong>胜负判定：</strong>最终获得对方所有8张牌的一方获胜</li>
                    </ul>
                </div>
            </div>

            <!-- 游戏技巧 -->
            <div class="tips-section">
                <h3 class="tips-title">
                    <span>💡</span>
                    游戏技巧
                </h3>
                <div class="tip-item">
                    <div class="tip-icon">🎯</div>
                    <div class="tip-text">优先翻出高数字的卡牌，增加获胜概率</div>
                </div>
                <div class="tip-item">
                    <div class="tip-icon">🔄</div>
                    <div class="tip-text">记住已翻出的卡牌位置，制定翻牌策略</div>
                </div>
                <div class="tip-item">
                    <div class="tip-icon">⚡</div>
                    <div class="tip-text">利用特殊规则，变形龙和小王虎是关键牌</div>
                </div>
                <div class="tip-item">
                    <div class="tip-icon">🎲</div>
                    <div class="tip-text">观察对手翻牌规律，预测剩余卡牌分布</div>
                </div>
            </div>
        </div>
    </div>

    <script>
        // 返回上一页
        function goBack() {
            window.history.back();
        }

        // 应用主题颜色
        function applyTheme(theme) {
            console.log('游戏规则页面应用主题:', theme);
            
            // 移除所有主题类
            const body = document.body;
            const allThemes = ['theme-blue', 'theme-green', 'theme-orange', 'theme-purple', 
                              'theme-pink', 'theme-red', 'theme-yellow', 'theme-cyan', 
                              'theme-lime', 'theme-indigo', 'theme-teal', 'theme-rose', 
                              'theme-amber', 'theme-emerald', 'theme-sky', 'theme-violet'];
            
            allThemes.forEach(themeClass => {
                body.classList.remove(themeClass);
            });
            
            // 添加新主题类
            if (theme && theme !== 'default') {
                body.classList.add('theme-' + theme);
                console.log('已应用主题类:', 'theme-' + theme);
            }
        }

        // 检查并同步主题
        function checkAndSyncTheme() {
            const savedTheme = localStorage.getItem('selectedTheme');
            const lastUpdateTime = localStorage.getItem('themeUpdateTime');
            
            if (savedTheme && lastUpdateTime) {
                console.log('检测到保存的主题:', savedTheme);
                applyTheme(savedTheme);
            }
        }

        // 监听主题变化
        function startThemeListener() {
            let lastThemeUpdateTime = localStorage.getItem('themeUpdateTime') || '0';
            
            // 定期检查主题更新
            setInterval(() => {
                const currentThemeUpdateTime = localStorage.getItem('themeUpdateTime') || '0';
                
                if (currentThemeUpdateTime !== lastThemeUpdateTime) {
                    console.log('检测到主题更新');
                    lastThemeUpdateTime = currentThemeUpdateTime;
                    
                    const savedTheme = localStorage.getItem('selectedTheme');
                    if (savedTheme) {
                        console.log('同步新主题:', savedTheme);
                        applyTheme(savedTheme);
                    }
                }
            }, 500);
        }

        // 页面加载时初始化
        document.addEventListener('DOMContentLoaded', function() {
            console.log('游戏规则页面加载完成');
            
            // 检查并同步主题
            checkAndSyncTheme();
            
            // 启动主题监听器
            startThemeListener();
            
            // 监听页面可见性变化
            document.addEventListener('visibilitychange', function() {
                if (!document.hidden) {
                    console.log('页面变为可见，检查主题更新');
                    checkAndSyncTheme();
                }
            });
            
            console.log('主题同步功能已启动');
            console.log('当前保存的主题:', localStorage.getItem('selectedTheme'));
            console.log('主题更新时间:', localStorage.getItem('themeUpdateTime'));
        });
    </script>
</body>
</html>
